<template>
	<view class="page">
		<initlate :leaders="leader" :participant="participants" @peopleclose="peopleChange"></initlate>
	</view>
</template>

<script>
	import initlate from '../component/initlate/initlate';
	import * as api from '@/utils/api.js';
	export default {
		components: {
			initlate,
		},
		data() {
			return {
				refreshType:false, // 刷新状态
				leader:[],
				participants:[],
			}
		},
		onLoad(e) {
			
		},
		onShow() {
			const token = uni.getStorageSync('token');
			if(!token){
				uni.showToast({
					title: '请先登录',
					icon: 'none',
					duration: 2000,
					complete(res) {
						setTimeout(function(){
							uni.reLaunch({
								url: '/subcontractList/login/index/index'
							});
						},2000);
						
					}
				});
			}
			let personList = getApp().globalData.personList;
			this.leader = personList.leader;
			this.participants = personList.participants;
			console.log('show',personList);
			console.log('leader',this.leader);
			console.log('participants',this.participants)
		},
		onUnload(){
			console.log('unload');
			getApp().globalData.personList = {leader:[],participants:[],assignment:[]};
		},
		methods: {
			peopleChange:function(e){
				console.log('close',e);
				if(e.key == 'leader'){
					this.leaderCloseChange(e.index);
				}else if(e.key == 'participant'){
					this.participantsCloseChange(e.index);
				}
			},
			/**
			 * 负责人关闭按钮点击触发事件
			 */
			leaderCloseChange:function(e){
				let personList = getApp().globalData.personList;
				personList.leader.splice(e, 1);
				getApp().globalData.personList = personList;
				this.leader = personList.leader;
			},
			/**
			 * 参与人关闭按钮点击触发事件
			 */
			participantsCloseChange:function(e){
				let personList = getApp().globalData.personList;
				personList.participants.splice(e, 1);
				getApp().globalData.personList = personList;
				this.participants = personList.participants;
			},
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #fafafa;
	}
</style>
